package gui;

import java.io.IOException;
import java.util.Observer;
import javax.swing.JOptionPane;
import server.SyncServer;

public class ServerController {
	
	private SyncServer server;

	public void startServer( Observer observer ) {
		try {
			server = new SyncServer();
			server.addObserver(observer);
			Thread t = new Thread(server);
			t.start();
		} catch (IOException e) {
			JOptionPane.showMessageDialog(null, "Could not create ServerSocket, change settings and try again !\n"+e.getLocalizedMessage(),
				"Initialization Error", JOptionPane.ERROR_MESSAGE );
		}
	}

	public void stopServer() {
		if( server != null ) {
			server.stopListening();
			server = null;
		}
	}

}
